const config = require("../../config");
import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/login",
    component: () => import("@/views/login"),
    meta: {
      title: "登录页",
      left: false,
    },
  },
  {
    path: "/home",
    component: () => import("@/views/home"),
    meta: {
      title: config["appName"],
      left: false,
    },
  },
  {
    path: "/postWish",
    component: () => import("@/views/postWish"),
    meta: {
      title: "发布心愿",
      left: true,
    },
  },
  {
    path: "/seekHelp",
    component: () => import("@/views/seekHelp"),
    meta: {
      title: "心愿广场",
      left: true,
    },
  },
  {
    path: "/myWish",
    component: () => import("@/views/myWish"),
    meta: {
      title: "我的心愿",
      left: true,
    },
  },
  {
    path: "/honorRoll",
    component: () => import("@/views/honorRoll"),
    meta: {
      title: "光荣榜",
      left: true,
    },
  },
  {
    path: "/wishDetail",
    component: () => import("@/views/wishDetail"),
    meta: {
      title: "心愿单子",
      left: true,
    },
  },
];

const router = new VueRouter({
  scrollBehavior: () => ({ y: 0 }),
  mode: "hash",
  routes,
});
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
});

export default router;
